Release 10.1A: OpenEdge Data Management:
SQL Development
Handling cycles in referential integrity
A cycle exists when a series of primary-key-foreign-key relationships exists within a group of tables in a database.
In Example 5–23, the
parts.distrib_nocolumn references the primary key of thedistributortable, and thedistributor.part_nocolumn references the primary key of the parts table. Each of the tables references the other, forming a cycle.
A special case of the cycle in referential integrity occurs when a foreign key of a table references the primary key of the same table. Example 5–24 shows this single-table cycle.
Creating tables in cycles
Use the following procedure to create a table cycle.
![]()
To create a table cycle:
- Create the first table with a reference to a table that is not yet created. Although the
CREATE TABLEsucceeds, it is marked incomplete. TheINSERT,UPDATE,SELECT, andDELETEoperations are not allowed on an incomplete table.- Create the referenced table with a primary or candidate key. The definition of the referencing table becomes complete. If the second table also contains a foreign key that references a table that is not yet created, this second table is also marked incomplete. This process continues until you create the last table.
Inserting rows in a cycle
Use the following procedure to insert rows in a cycle.
![]()
To insert rows into tables that form a cycle:
- Insert rows into one of the tables that forms the cycle, with
NULLvalues in the foreign key columns. If the foreign key isNULL, the database does not check for a match between the foreign key and the corresponding primary key. The insert succeeds. This is the referencing table.- Update or insert the values in the primary keys of the second, referenced table.
- Update the foreign key values of the previous table, the referencing table.
Example 5–25 shows how to insert or update values into the
employeetable. This table forms a single-table cycle. First insertNULLinto themgr_codecolumn. After you insert rows, update the values of themgr_codecolumn.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |